'''
version: V0.1
Author: xubing
Date: 2020-11-18 18:51:34
LastEditors: xubing
LastEditTime: 2020-12-14 18:22:13
Description: 
'''

import time


def timer(func):
    def inner(*args, **kwargs):
        start_time = time.time()
        fn = func(*args, **kwargs)
        end_time = time.time()
        cost_time = end_time - start_time
        print('--' * 10)
        print('运行{}程序耗时:{}'.format(func.__name__, get_beauty_time(cost_time)))
        print('--' * 10)
        return fn

    return inner


def get_beauty_time(seconds):
    if seconds < 0:
        return 'N/A'
    elif seconds < 1:
        return '不到1秒'
    elif seconds < 60:
        return "%.01f秒" % (seconds)
    elif seconds < 60 * 60:
        return "%s分%s秒" % (str(int(seconds / 60)), str(int(seconds % 60)))
    else:
        return "%s小时%s分" % (str(int(seconds / 60)), str(int(seconds % 60)))


def get_year_quarter(date_str):
    year = int(date_str[0:4])
    month = int(date_str[5:7])
    quarter = month / 3
    return year, quarter


if __name__ == '__main__':
    seconds = 9999
    print(get_beauty_time(seconds))
